{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import geopandas\n",
    "from buckaroo.geopandas_buckaroo import GeopandasBuckarooWidget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "world_df = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "world_df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3",
   "metadata": {},
   "source": [
    "# Use GeopandasSVGBuckarooWidget to see renderings of geometry"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from buckaroo.geopandas_buckaroo import GeopandasSVGBuckarooWidget\n",
    "GeopandasSVGBuckarooWidget(world_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "abbrev_geo_obj = {\n",
    "    \"type\": \"FeatureCollection\",\n",
    "    \"features\": [\n",
    "        { \"id\": \"0\",\n",
    "          \"type\": \"Feature\",\n",
    "          \"properties\": { \"sovereignt\": \"Ethiopia\"},\n",
    "          \"geometry\": {\n",
    "              \"type\": \"Polygon\",\n",
    "              \"coordinates\": [[[ 47.78, 8.00],\n",
    "                               [ 44.96, 5.00],\n",
    "                               [ 43.66, 4.95],\n",
    "                               [ 46.94, 7.99],\n",
    "                               [ 47.78, 8.00]]]}},\n",
    "        { \"id\": \"1\",\n",
    "          \"type\": \"Feature\",\n",
    "          \"properties\": { \"sovereignt\": \"South Sudan\"},\n",
    "          \"geometry\": {\n",
    "          \"type\": \"Polygon\",\n",
    "          \"coordinates\": [[[ 30.83, 3.50],\n",
    "                           [ 29.95, 4.17],\n",
    "                           [ 29.71, 4.60],\n",
    "                           [ 29.15, 4.38],\n",
    "                           [ 30.83, 3.50]]]}},\n",
    "        { \"id\": \"2\",\n",
    "          \"type\": \"Feature\",\n",
    "          \"properties\": { \"sovereignt\": \"Somalia\"},\n",
    "          \"geometry\": {\n",
    "              \"type\": \"Polygon\",\n",
    "              \"coordinates\": [[[ 41.58, -1.68],\n",
    "                               [ 40.93, -0.85],\n",
    "                               [ 40.95,  2.78],\n",
    "                               [ 41.85,  3.91],\n",
    "                               [ 42.13,  4.23],\n",
    "                               [ 41.58, -1.68]]]}}]}\n",
    "abbrev_df = geopandas.GeoDataFrame.from_features(abbrev_geo_obj)\n",
    "abbrev_df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6",
   "metadata": {},
   "source": [
    "## Tweaking row height\n",
    "Shapely emits SVG graphics, they seem to vary in height,  Buckaroo needs a global rowHeight, here is how to set it\n",
    "We also made buckaroo larger"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "nybb_df = geopandas.read_file(geopandas.datasets.get_path('nybb'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "GeopandasBuckarooWidget(nybb_df, component_config={'height_fraction':1.2},\n",
    "                        extra_grid_config={'rowHeight':305})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "geojson = requests.get('https://gist.githubusercontent.com/chbrandt/bb64d9a6fc00a89d7410e6db8d126dfe/raw/8bc7a45c57e1c701618c940525d83bee80fd6b90/africa.geojson')\n",
    "assert 200 <= geojson.status_code < 400\n",
    "gdf = geopandas.GeoDataFrame.from_features(geojson.json())\n",
    "gdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))\n",
    "cities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "bigdf = pd.concat([world_df] *100)\n",
    "bigdf['newindex'] = np.arange(17700)\n",
    "bigdf.set_index('newindex')\n",
    "print(len(bigdf))\n",
    "%timeit GeopandasBuckarooWidget(bigdf[:1500])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
